﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

/// <summary>
/// The search box user control provides the
/// user with a textbox and search button to search
/// all the content of the website.
/// </summary>
public partial class App_Common_UserControls_SearchBox : System.Web.UI.UserControl
{
    /// <summary>
    /// When the page first loads we need to set the
    /// initial text of the search textbox which is specified
    /// in the website's web.config file.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (ConfigurationManager.AppSettings["SearchDefaultText"] != null)
                txtSearch.Text = ConfigurationManager.AppSettings["SearchDefaultText"].ToString();
        }
    }

    /// <summary>
    /// When the user clicks the search button we save
    /// the search text into a session variable and redirect
    /// the user to the search results screen.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Session["SearchString"] = txtSearch.Text;
        Response.Redirect("Search.aspx", true);
    }
}
